package cn.stacey.day11;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import javafx.scene.chart.Axis;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart.Data;
import javafx.scene.chart.XYChart.Series;

public class ChartUtils1 {
	//key value  姓名对应的分数
	public static LineChart<String,Number> createLineChart(String title,Map<String,Number> scores){
		Axis<String> xAxis=new CategoryAxis();
		Axis<Number> yAxis=new NumberAxis();
		xAxis.setLabel("姓名");
		yAxis.setLabel("成绩");

		LineChart<String,Number> linechart=new LineChart<>(xAxis,yAxis);

		Series<String,Number> series=new Series<>();
		for(Entry<String,Number> entry:scores.entrySet()) {
			series.getData().add(new Data<String,Number>(entry.getKey(),entry.getValue()));
		}
//		series.getData().add(new Data<String,Number>("于辉",35));
//		series.getData().add(new Data<String,Number>("张辉",38));
//		series.getData().add(new Data<String,Number>("陈小",33));
		series.setName(title);
		linechart.getData().add(series);
		return linechart;
		
	}
	
	public static List<LineChart<String,Number>> createLineChart1(
//		String title1,Map<String,Number> scores1,
//		String title2,Map<String,Number> scores2
			Map<String,Map<String,Number>> map
			
			
			){
		Axis<String> xAxis=new CategoryAxis();
		Axis<Number> yAxis=new NumberAxis();
		xAxis.setLabel("姓名");
		yAxis.setLabel("成绩");
//		LineChart<String,Number> linechart=new LineChart<>(xAxis,yAxis);
//		Series<String,Number> series=new Series<>();
		List<LineChart<String,Number>> charts=new ArrayList<>();
				for(Entry<String,Map<String,Number>> entry:map.entrySet()) {
				String title=entry.getKey();
				Map<String, Number> scores=entry.getValue();
				LineChart<String,Number> linechart=createLineChart(title,scores);
				charts.add(linechart);
				}
				return charts;
		
	}
}
